<template>
  <div id="app">
    <div class="content">
      <keep-alive exclude="Detail" include="Apply,AllGame,StartServer,GameActivitie,VipQuery,WithdrawalDetails,WebGame,DiscountGame,BtGame,Home,DataManagement,Message,PageTools,StopServer">
        <router-view></router-view>
      </keep-alive>
    </div>
    <main-tab-bar/>
    <!-- 全局加载组件 -->
    <van-loading class="loading"  type="spinner" color="#666666" size="40px" vertical v-show="LOADING">加载中...</van-loading>
  </div>
</template>

<script>
import MainTabBar from './components/content/mainTabBar/MainTabBar.vue'
import { mapState } from 'vuex'

export default {
  components: { 
    MainTabBar,
  },
  created () {
    // 在页面加载时读取sessionStorage里的状态信息
    if (sessionStorage.getItem('store')) {
      this.$store.replaceState(
        Object.assign(
          {},
          this.$store.state,
          JSON.parse(sessionStorage.getItem('store'))
        )
      )
    }
    //  pagehide 解决ios移动端不支持beforeunload,安卓端两个都可以用
    //  在页面刷新时将vuex里的信息保存到sessionStorage里
    window.addEventListener('pagehide', () => {
      sessionStorage.setItem('store', JSON.stringify(this.$store.state))
    })
  },
  computed: {
    ...mapState([
      'LOADING'
    ])
  },
}
</script>

<style scoped>
.loading {
  z-index: 999;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.content {
  height: 100%;
  min-height: 100%;
  background: #ffffff;
}
</style>